package cn.com.cfae.iras.doc.analyze.components.integrity;

import cn.com.cfae.iras.doc.analyze.beans.web.ContentAndPosition;
import cn.com.cfae.iras.doc.analyze.beans.web.Detail;
import cn.com.cfae.iras.doc.analyze.components.BaseComponent;
import cn.com.cfae.iras.doc.analyze.components.beans.ComponentResult;
import cn.com.cfae.iras.doc.analyze.parse.kv.KVText;
import cn.com.cfae.iras.doc.analyze.parse.model.ChapterModel;
import cn.com.cfae.iras.doc.analyze.parse.model.ExtractBizModel;
import cn.com.cfae.iras.doc.analyze.parse.model.ExtractItem;
import cn.com.cfae.iras.doc.analyze.parse.model.PageModel;
import cn.com.cfae.iras.doc.analyze.parse.model.SectionModel;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

/**
 * Created by 佟媛媛 on 18/11/23.
 * 检查关键字是否存在 完整性 子表
 */

@Component("I1028")
@Scope("prototype")
public class I1028 extends BaseComponent {
    private static Logger log = LoggerFactory.getLogger(I1028.class);

    private String keyword;//关键字

    public String getKeyword() {
        return keyword;
    }

    public void setKeyword(String keyword) {
        this.keyword = keyword;
    }

    private String chapterId;//章节

    public String getChapterId() {
        return chapterId;
    }

    public void setChapterId(String chapterId) {
        this.chapterId = chapterId;
    }


    @Override
    public List<ComponentResult> handlerM() {
        return null;
    }

    public Map _handlerM(){
        return ifKeywordExist2(getCatalogId());
    }
    public Map _handlerBM(){
        String catalogId = getCatalogId();
        if(StringUtils.isNotEmpty(getCatalogId())){
            if(getCatalogId().split("-").length>1){
                catalogId = "BM-"+getCatalogId().split("-")[1];
            }else if(getCatalogId().split("-").length==1){
                catalogId = "BM";
            }
        }
        setCatalogId(catalogId);
        return _handlerM();
    }
    public Map _handlerDM(){
        String catalogId = getCatalogId();
        if(StringUtils.isNotEmpty(getCatalogId())){
            if(getCatalogId().split("-").length>1){
                catalogId = "DM-"+getCatalogId().split("-")[1];
            }else if(getCatalogId().split("-").length==1){
                catalogId = "DM";
            }
        }
        setCatalogId(catalogId);
        return _handlerM();
    }
    public Map _handlerBDM(){
        String catalogId = getCatalogId();
        if(StringUtils.isNotEmpty(getCatalogId())){
            if(getCatalogId().split("-").length>1){
                catalogId = "BDM-"+getCatalogId().split("-")[1];
            }else if(getCatalogId().split("-").length==1){
                catalogId = "BDM";
            }
        }
        setCatalogId(catalogId);
        return _handlerM();
    }


    /**
     * @auth 佟媛媛
     * @date 18/10/26 下午2:54
     * @desc 跨行判断关键字是否存在且返回文本和坐标
     */
    public Map ifKeywordExist2(String catalogId){
        Map rs = new HashMap();
        ChapterModel chapterModel = getChapterModel(catalogId);
        int pageNum = chapterModel.getStartPage();
        //在标题中判断
        rs = ifInTitle(chapterModel,pageNum);
        boolean exist = (boolean)rs.get("exist");
        //在业务模型判断
        if(!exist){
            rs = ifInModelMap(chapterModel,pageNum);
            exist = (boolean)rs.get("exist");
        }
        if(!exist){//在章节文本中判断
            rs = ifInContent(chapterModel,pageNum);
        }
        return rs;
    }

    /**
     * @auth 佟媛媛
     * @date 18/12/4 下午5:57
     * @desc 在业务模型中判断
     */
    private Map ifInModelMap(ChapterModel chapterModel,int pageNum){
        Map rs = new HashMap();
        boolean boo = false;
        List<ContentAndPosition> contentAndPositionList = new ArrayList<ContentAndPosition>();
        Map<String, ExtractBizModel> extractBizModelMap = chapterModel.getExtractBizModelMap();
        if(MapUtils.isNotEmpty(extractBizModelMap)){
            for(Map.Entry<String, ExtractBizModel> entry : extractBizModelMap.entrySet()){
                if(boo) break;
                String key = entry.getKey();
                if(entry.getValue()!=null){
                    List<ExtractItem> extractItemList = entry.getValue().getExtractItemList();
                    if(!CollectionUtils.isEmpty(extractItemList)){
                        for(ExtractItem item :extractItemList){
                            if(boo) break;
                            KVText kvTextKey = item.getKey();
                            //判断key名称是否包含关键字
//                            if(kvTextKey!=null && !StringUtils.isEmpty(kvTextKey.getText()) && kvTextKey.getTextLayout()!=null){
//                                Map map = ifContain(kvTextKey.getText());
                            if(kvTextKey!=null && kvTextKey.getTextLayout()!=null){
//                                Map map = ifContain(kvTextKey.getTextLayout().getText());
                                Map map = ifContain(item.getSynonyms());
                                boolean pp = (boolean)map.get("exist");
                                String content = (String)map.get("text");
                                if(pp){
                                    boo = true;
                                    ContentAndPosition contentAndPosition = new ContentAndPosition();
                                    contentAndPosition.setContent(kvTextKey.getTextLayout().getText());
                                    contentAndPosition.setX(kvTextKey.getTextLayout().getLeft());
                                    contentAndPosition.setY(kvTextKey.getTextLayout().getTop());
                                    contentAndPosition.setPageNum(kvTextKey.getTextLayout().getPageNumber());
                                    contentAndPositionList.add(contentAndPosition);
                                }
                            }
                        }
//                        在value中判断关键字，因为value坐标不准，所以注释掉该段代码
//                        for(ExtractItem item :extractItemList){
//                            if(boo) break;
//                            KVText kvTextValue = item.getValue();
//                            //判断value是否包含关键字
//                            if(kvTextValue!=null && !org.springframework.util.StringUtils.isEmpty(kvTextValue.getText()) && kvTextValue.getTextLayout()!=null){
//                                Map map = ifContain(kvTextValue.getText());
//                                boolean pp = (boolean)map.get("exist");
//                                String content = (String)map.get("text");
//                                if(pp){
//                                    boo = true;
//                                    ContentAndPosition contentAndPosition = new ContentAndPosition();
//                                    contentAndPosition.setContent(content);
//                                    contentAndPosition.setX(kvTextValue.getTextLayout().getLeft());
//                                    contentAndPosition.setY(kvTextValue.getTextLayout().getTop());
//                                    contentAndPosition.setPageNum(kvTextValue.getTextLayout().getPageNumber());
//                                    contentAndPositionList.add(contentAndPosition);
//                                }
//                            }
//                        }
                    }
                }
            }
        }
        rs.put("contentAndPositionList",contentAndPositionList);
        rs.put("exist",contentAndPositionList.size()==0?false:true);
        rs.put("pageNum",pageNum);
        return rs;
    }

    /**
     * @auth 佟媛媛
     * @date 18/12/3 下午8:01
     * @desc  在标题中判断
     */
    private Map ifInTitle(ChapterModel chapterModel,int pageNum){
        Map rs = new HashMap();
        List<ContentAndPosition> contentAndPositionList = new ArrayList<ContentAndPosition>();
        List<SectionModel> sectionModelList = chapterModel.getSectionModelList();
        ContentAndPosition contentAndPosition =  getContentAndPosition(sectionModelList);
        if(contentAndPosition!=null) contentAndPositionList.add(contentAndPosition);
        rs.put("contentAndPositionList",contentAndPositionList);
        rs.put("exist",contentAndPositionList.size()==0?false:true);
        rs.put("pageNum",pageNum);
        return rs;
    }

    private ContentAndPosition getContentAndPosition(List<SectionModel> sectionModelList){
        if(CollectionUtils.isEmpty(sectionModelList)){
            return null;
        }
        for(SectionModel sectionModel : sectionModelList){
            if(!org.springframework.util.StringUtils.isEmpty(sectionModel.getTitle()) && sectionModel.getTextLayout()!=null){
                Map map = ifContain(sectionModel.getTitle());
                boolean pp = (boolean)map.get("exist");
                String content = (String)map.get("text");
                if(pp){
                    ContentAndPosition contentAndPosition = new ContentAndPosition();
                    contentAndPosition.setContent(sectionModel.getTextLayout().getText());
                    contentAndPosition.setX(sectionModel.getTextLayout().getLeft());
                    contentAndPosition.setY(sectionModel.getTextLayout().getTop());
                    contentAndPosition.setPageNum(sectionModel.getTextLayout().getPageNumber());
                    return contentAndPosition;
                }else{
                    if(!org.springframework.util.StringUtils.isEmpty(sectionModel.getChildSectionModelList())){
                        ContentAndPosition contentAndPosition =  getContentAndPosition(sectionModel.getChildSectionModelList());
                        if(contentAndPosition!=null){
                            return contentAndPosition;
                        }
                    }
                }
            }
        }
        return null;
    }



    /**
     * @auth 佟媛媛
     * @date 18/12/3 下午8:01
     * @desc 在章节中判断
     */
    private Map ifInContent(ChapterModel chapterModel,int pageNum){
        Map rs = new HashMap();
        List<ContentAndPosition> contentAndPositionList = new ArrayList<ContentAndPosition>();
        List<PageModel> pageModelList = chapterModel!=null?chapterModel.getPageModelList():null;
        if(!CollectionUtils.isEmpty(pageModelList)){
            boolean boo = false;
            for(PageModel pageModel : pageModelList){
                if(boo){
                    break;
                }
                JsonArray jsonTextDataArray = pageModel.getJsonTextData()!=null?pageModel.getJsonTextData().getAsJsonArray():null;
                if(jsonTextDataArray!=null){
                    for(JsonElement element : jsonTextDataArray){
                        if(boo){
                            break;
                        }
                        JsonArray data = element.getAsJsonObject()!=null?element.getAsJsonObject().getAsJsonArray("data"):null;//当页文本
                        if(data!=null && data.size()>1){
                            List<ContentAndPosition> __contentAndPositionList = handleText(data,pageModel);
                            contentAndPositionList.addAll(__contentAndPositionList);
                            if(__contentAndPositionList.size()>0)  boo = true;
                        }
                    }
                }
            }
        }
        rs.put("contentAndPositionList",contentAndPositionList);
        rs.put("exist",contentAndPositionList.size()==0?false:true);
        rs.put("pageNum",pageNum);
        return rs;
    }


    /**
     * @auth 佟媛媛
     * @date 18/11/23 下午5:28
     * @desc 数据库关键字及同义词以|分割
     */
    private Map ifContain(String text){
        Map map = new HashMap();
        String[] keywords = getKeyword().split("\\|");
        map.put("exist",false);
        map.put("text",keywords[0]);
        for(String keyword : keywords){
            if(stringFilter(text.replace(" ","")).contains(stringFilter(keyword))){
                map.put("exist",true);
                map.put("text",keyword);
                break;
            }
        }
        return map;
    }

    /**
     * @auth 佟媛媛
     * @date 18/11/23 下午5:28
     * @desc 数据库关键字及同义词以|分割
     */
    private Map ifContain(String[] text){
        Map map = new HashMap();
        boolean boo = false;
        String[] keywords = getKeyword().split("\\|");
        map.put("exist",false);
        map.put("text",keywords[0]);
        for(String keyword : keywords){
            if(boo) break;
            for(String t:text){
                if(boo) break;
                if((t).equals((keyword))){
                    boo = true;
                    map.put("exist",true);
                    map.put("text",keyword);
                    break;
                }
            }
        }
        return map;
    }

    /**
     * @auth 佟媛媛
     * @date 18/11/28 下午5:02
     * @desc 检查到第一个即返回
     */
    private List<ContentAndPosition> handleText(JsonArray data,PageModel pageModel){
        List<ContentAndPosition> _contentAndPositionList = new ArrayList<ContentAndPosition>();
        int pageNum = pageModel.getPageNumber();
        PageModel last = getPageModel(getCatalogId(),pageNum-1);
        PageModel next = getPageModel(getCatalogId(),pageNum+1);
        JsonObject lastLine = getLastLine(last);
        JsonObject firstLine = getFirstLine(next);
        for(int i=0;i<data.size()-3;i++){
            StringBuilder text = new StringBuilder();
            JsonObject line1 = returnOne(data.get(i).getAsJsonArray());//returnOneExpectTable(data.get(i).getAsJsonArray(),pageModel);
            JsonObject line2 = returnOne(data.get(i+1).getAsJsonArray());//returnOneExpectTable(data.get(i+1).getAsJsonArray(),pageModel);
            JsonObject line3 = returnOne(data.get(i+2).getAsJsonArray());//returnOneExpectTable(data.get(i+2).getAsJsonArray(),pageModel);
            text.append(line1.get("text").getAsString()).append(line2.get("text").getAsString()).append(line3.get("text").getAsString());
            Map map = ifContain(text.toString());
            boolean pp = (boolean)map.get("exist");//text.toString().contains(getKeyword());
            String content = (String)map.get("text");
            if(pp){
                List<ContentAndPosition> contentAndPositionList = line3(text.toString(),content,line1,line2,line3,pageNum);
                _contentAndPositionList.addAll(contentAndPositionList);
                break;
            }else{
                if(i==0 && lastLine!=null){//上一页最后一行
                    text=new StringBuilder();
                    text.append(lastLine.get("text").getAsString()).append(line1.get("text").getAsString()).append(line2.get("text").getAsString());
                    map = ifContain(text.toString());
                    pp = (boolean)map.get("exist");//text.toString().contains(getKeyword());
                    content = (String)map.get("text");
                    if(pp){
                        List<ContentAndPosition> contentAndPositionList = line3(text.toString(),content,lastLine,line1,line2,pageNum-1);
                        _contentAndPositionList.addAll(contentAndPositionList);
                        break;
                    }
                }else if(i==data.size()-4 && firstLine!=null){//下一页第一行
                    text=new StringBuilder();
                    text.append(line2.get("text").getAsString()).append(line3.get("text").getAsString()).append(firstLine.get("text").getAsString());
                    map = ifContain(text.toString());
                    pp = (boolean)map.get("exist");//text.toString().contains(getKeyword());
                    content = (String)map.get("text");
                    if(pp){
                        List<ContentAndPosition> contentAndPositionList = line3(text.toString(),content,line2,line3,firstLine,pageNum+1);
                        _contentAndPositionList.addAll(contentAndPositionList);
                        break;
                    }
                }
            }
        }
        return _contentAndPositionList;
    }



    private List<ContentAndPosition> line3(String text,String content,JsonObject obj1,JsonObject obj2,JsonObject obj3,int pageNum){
        List<ContentAndPosition> _contentAndPositionList = new ArrayList<>();
        text = text.replace(",","，").replace(" ","");
        int i0 = obj1.get("text").getAsString().replace(",","，").replace(" ","").length();
        int i1 = obj1.get("text").getAsString().replace(",","，").replace(" ","").length()+obj2.get("text").getAsString().replace(",","，").replace(" ","").length();
        int i2 = text.indexOf(content);
        int i3 = text.indexOf(content)+content.length();
        if(i0!=-1 && i1!=-1 && i2!=-1 && i3!=-1){
            if(i2<i3 && i3<=i0 && i0<=i1){//关键字在第一行
                ContentAndPosition contentAndPosition = new ContentAndPosition();
                String _content = text.substring(i2,i3);
                contentAndPosition.setContent(_content);
                contentAndPosition.setX(obj1.get("left").getAsDouble());
                contentAndPosition.setY(obj1.get("top").getAsDouble());
                contentAndPosition.setPageNum(pageNum);
                if(!(obj1.get("left").getAsDouble()==0 && obj1.get("top").getAsDouble()==0)){
                    _contentAndPositionList.add(contentAndPosition);
                }
            }else if(i0<=i2 && i2<i3 && i3<=i1){//关键词在第二行
                ContentAndPosition contentAndPosition = new ContentAndPosition();
                String _content = text.substring(i2,i3);
                contentAndPosition.setContent(_content);
                contentAndPosition.setX(obj2.get("left").getAsDouble());
                contentAndPosition.setY(obj2.get("top").getAsDouble());
                contentAndPosition.setPageNum(pageNum);
                if(!(obj2.get("left").getAsDouble()==0 && obj2.get("top").getAsDouble()==0)){
                    _contentAndPositionList.add(contentAndPosition);
                }
            }else if(i0<=i1 && i1<=i2 && i2<i3){//关键词在第三行
                ContentAndPosition contentAndPosition = new ContentAndPosition();
                String _content = text.substring(i2,i3);
                contentAndPosition.setContent(_content);
                contentAndPosition.setX(obj3.get("left").getAsDouble());
                contentAndPosition.setY(obj3.get("top").getAsDouble());
                contentAndPosition.setPageNum(pageNum);
                if(!(obj3.get("left").getAsDouble()==0 && obj3.get("top").getAsDouble()==0)){
                    _contentAndPositionList.add(contentAndPosition);
                }
            }else if(i2<=i0 && i0<=i3 && i3<=i1){//关键词夸前两行
                ContentAndPosition contentAndPosition2 = new ContentAndPosition();
                String content2 = text.substring(i2,i0);
                contentAndPosition2.setContent(content2);
                contentAndPosition2.setX(obj1.get("left").getAsDouble());
                contentAndPosition2.setY(obj1.get("top").getAsDouble());
                contentAndPosition2.setPageNum(pageNum);
                if(!(obj1.get("left").getAsDouble()==0 && obj1.get("top").getAsDouble()==0)){
                    _contentAndPositionList.add(contentAndPosition2);
                }
                ContentAndPosition contentAndPosition3 = new ContentAndPosition();
                String content3 = text.substring(i0,i3);
                contentAndPosition3.setContent(content3);
                contentAndPosition3.setX(obj2.get("left").getAsDouble());
                contentAndPosition3.setY(obj2.get("top").getAsDouble());
                contentAndPosition3.setPageNum(pageNum);
                if(!(obj2.get("left").getAsDouble()==0 && obj2.get("top").getAsDouble()==0)){
                    _contentAndPositionList.add(contentAndPosition3);
                }
            }else if(i0<=i2 && i2<=i1 && i1<=i3){//关键字夸后两行
                ContentAndPosition contentAndPosition2 = new ContentAndPosition();
                String content2 = text.substring(i2,i1);
                contentAndPosition2.setContent(content2);
                contentAndPosition2.setX(obj2.get("left").getAsDouble());
                contentAndPosition2.setY(obj2.get("top").getAsDouble());
                contentAndPosition2.setPageNum(pageNum);
                if(!(obj2.get("left").getAsDouble()==0 && obj2.get("top").getAsDouble()==0)){
                    _contentAndPositionList.add(contentAndPosition2);
                }
                ContentAndPosition contentAndPosition3 = new ContentAndPosition();
                String content3 = text.substring(i1,i3);
                contentAndPosition3.setContent(content3);
                contentAndPosition3.setX(obj3.get("left").getAsDouble());
                contentAndPosition3.setY(obj3.get("top").getAsDouble());
                contentAndPosition3.setPageNum(pageNum);
                if(!(obj3.get("left").getAsDouble()==0 && obj3.get("top").getAsDouble()==0)){
                    _contentAndPositionList.add(contentAndPosition3);
                }
            }else if(i2<=i0 && i0<=i1 && i1<=i3){//关键词夸三行
                ContentAndPosition contentAndPosition1 = new ContentAndPosition();
                String content1 = text.substring(i2,i0);
                contentAndPosition1.setContent(content1);
                contentAndPosition1.setX(obj1.get("left").getAsDouble());
                contentAndPosition1.setY(obj1.get("top").getAsDouble());
                contentAndPosition1.setPageNum(pageNum);
                if(!(obj1.get("left").getAsDouble()==0 && obj1.get("top").getAsDouble()==0)){
                    _contentAndPositionList.add(contentAndPosition1);
                }
                ContentAndPosition contentAndPosition2 = new ContentAndPosition();
                String content2 = text.substring(i0,i1);
                contentAndPosition2.setContent(content2);
                contentAndPosition2.setX(obj2.get("left").getAsDouble());
                contentAndPosition2.setY(obj2.get("top").getAsDouble());
                contentAndPosition2.setPageNum(pageNum);
                if(!(obj2.get("left").getAsDouble()==0 && obj2.get("top").getAsDouble()==0)){
                    _contentAndPositionList.add(contentAndPosition2);
                }
                ContentAndPosition contentAndPosition3 = new ContentAndPosition();
                String content3 = text.substring(i1,i3);
                contentAndPosition3.setContent(content3);
                contentAndPosition3.setX(obj3.get("left").getAsDouble());
                contentAndPosition3.setY(obj3.get("top").getAsDouble());
                contentAndPosition3.setPageNum(pageNum);
                if(!(obj3.get("left").getAsDouble()==0 && obj3.get("top").getAsDouble()==0)){
                    _contentAndPositionList.add(contentAndPosition3);
                }
            }
        }
        return _contentAndPositionList;
    }


    /**
     * @auth 佟媛媛
     * @date 18/10/26 上午11:39
     * @desc 获取每页文本
     */
    private String getPageContent(JsonElement jsonTextData){
        StringBuilder content = new StringBuilder();
        JsonArray array = jsonTextData.getAsJsonArray();
        for(JsonElement element : array){
            JsonObject obj = element.getAsJsonObject();
            JsonArray data = obj.getAsJsonArray("data");//当页文本
            if(data!=null){
                for(JsonElement _element : data){
                    JsonArray _data = _element.getAsJsonArray();
                    JsonObject _obj = returnOne(_data);
                    String text = _obj.get("text").getAsString();
                    content.append(text);
                }
            }
        }
        return content.toString();
    }




    public Map getWebData(List<Map> mapList,String type){
        Map rs = new HashMap();
        Map<String,String> catalogMap = new HashMap();
        List<Detail> disclosedList = new ArrayList<>();
        List<Detail> undisclosedList = new ArrayList<>();
        List<Detail> seemDisclosedList = new ArrayList<>();
        if(!CollectionUtils.isEmpty(mapList)){
            for(Map map : mapList){
                String catalog_id = (String) map.get("catalogId");
                catalogMap.put(catalog_id,catalog_id);
            }
            for(String key : catalogMap.keySet()){
                List<Detail.Result> disclosedResults = new ArrayList<>();
                List<Detail.Result> undisclosedResults = new ArrayList<>();
                for(Map m : mapList){
                    Detail __map = new Detail();
                    String catalog_id = (String) m.get("catalogId");
                    String catalogId = StringUtils.isNotEmpty(catalog_id)&&catalog_id.split("-").length>1?(type+"-"+catalog_id.split("-")[1]):catalog_id;//因为子表在数据库中不区分M，BM，DM，DBM，所以title得需要拼接
                    String chapater_id = (String) m.get("chapterId");
                    String rule_name = (String) m.get("ruleTitle");
                    List<ContentAndPosition> contentAndPositionList = (List<ContentAndPosition>)m.get("contentAndPositionList");
                    boolean exist = (boolean)m.get("exist");
                    if(key.equals(catalog_id)){
                        __map.setCatalogId(catalogId);
                        __map.setRuleName(rule_name);
                        Integer pageNum = (Integer) m.get("pageNum");
                        Detail.Result _m = new Detail().new Result();
                        List<Detail.TextPosition> xys = new ArrayList<>();
                        if(!CollectionUtils.isEmpty(contentAndPositionList)){
                            for(ContentAndPosition contentAndPosition : contentAndPositionList){
                                pageNum = contentAndPosition.getPageNum();
                                Detail.TextPosition xy = new Detail().new TextPosition();
                                xy.setX(contentAndPosition.getX());
                                xy.setY(contentAndPosition.getY());
                                xy.setContent(contentAndPosition.getContent());
                                if(!(contentAndPosition.getX()==0 && contentAndPosition.getY()==0)) xys.add(xy);
                            }
                        }
                        _m.setUid(UUID.randomUUID().toString());
                        _m.setKeyword("关键字检查-"+(org.apache.commons.lang3.StringUtils.isNotEmpty((String)m.get("regulationDetail"))?m.get("regulationDetail").toString().split("\\|")[0]:m.get("regulationDetail")));//数据库中以|分割存储同义词，前端展示时只需显示第一个即可
                        _m.setRegulationId((String)m.get("regulationId"));
                        _m.setTextPosition(xys);
                        _m.setPageNum(pageNum);
                        _m.setChapterId(chapater_id);
                        if(exist){
                            _m.setAnnotationFlag(false);
                            _m.setPromptMessage("正确");
                            disclosedResults.add(_m);
                            __map.setResults(disclosedResults);
                            if(!ifInList(disclosedList,catalogId,rule_name)) disclosedList.add(__map);
                        }else{
                            _m.setAnnotationFlag(true);
                            _m.setPromptMessage((String)m.get("promptMessage"));
                            undisclosedResults.add(_m);
                            __map.setResults(undisclosedResults);
                            if(!ifInList(undisclosedList,catalogId,rule_name)) undisclosedList.add(__map);
                        }
                    }
                }

            }
        }
        rs.put("disclosed",disclosedList);
        rs.put("undisclosed",undisclosedList);
        rs.put("seem_disclosed",seemDisclosedList);
        return rs;
    }

    private boolean ifInList(List<Detail> list,String catalogId,String ruleName){
        if(CollectionUtils.isEmpty(list)){
            return false;
        }
        for(Detail d : list){
            if(!org.springframework.util.StringUtils.isEmpty(d.getCatalogId()) && d.getCatalogId().equals(catalogId) && d.getRuleName().equals(ruleName)){
                return true;
            }
        }
        return false;
    }



    @Override
    public List<ComponentResult> handlerBM() {
        return null;
    }

    @Override
    public List<ComponentResult> handlerDM() {
        return null;
    }

    @Override
    public List<ComponentResult> handlerBDM() {
        return null;
    }
}
